package com.wjj.app.fragment.viewpage1;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import com.wjj.app.R;
import com.wjj.app.activites.RecyclerViewActivity;

import static com.wjj.app.R.id.btn1;
import static com.wjj.app.R.id.btn2;

/**
 * Created by Wjj on 16/12/8.
 */
public class Fragment2 extends Fragment {

    private Button add;
    private Button remove;

    private MyInterface mMyInterface;

    public interface MyInterface {
        void add();
    }

    public void setListener(MyInterface myInterface) {
        this.mMyInterface = myInterface;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment1_v2, container, false);

        add = (Button) view.findViewById(btn1);
        remove = (Button) view.findViewById(btn2);

        FragmentManager fm = getActivity().getSupportFragmentManager();
        //“android:switcher:” + R.id.viewpager + “:0″
//        final MainFragment1 mainFragment1= (MainFragment1) fm.findFragmentByTag("android:switcher:"+R.id.fviewpage1+":1");
        add.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mMyInterface.add();
            }
        });

        view.findViewById(R.id.btn3).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(getActivity(), RecyclerViewActivity.class);
                startActivity(intent);
            }
        });
        return view;
    }


}
